package cn.qffj.memo.service;

import cn.qffj.memo.domain.User;
import cn.qffj.memo.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 杨友奇
 * @Time 2018/5/5
 */
@Service
public class UserService {
    @Autowired
    private UserRepository userRepository;

    public User save(User user) {
        return userRepository.save(user);
    }

    //通过用户名查询
    public User findByUserName(String usernName) {
        return userRepository.findByUserName(usernName);
    }



    //通过用户名密保问题进行判断
    public boolean existsByUserNameAndIssueResult(String userName, String issueRsult) {
        return userRepository.existsByUserNameAndIssueResult(userName, issueRsult);
    }

    //通过用户名信息判断
    public boolean existsByUserName(String userName) {
        return userRepository.existsByUserName(userName);
    }

    //通过密码判断
    public boolean existsByUserNameAndPassword(String username,String password) {
        return userRepository.existsByUserNameAndPassword(username,password);
    }

    //修改密码
    public User update(User user) {
        User user1 = userRepository.findByUserName(user.getUserName());
        System.out.println(user.getUserName());
        user1.setUserName(user.getUserName());
        user1.setUserGroup(user.getUserGroup());
        user1.setAccount(user.getAccount());
        user1.setPassword(user.getPassword());
        user1.setIssue(user.getIssue());
        return userRepository.save(user1);

    }
}
